package xyz.yq56.glue_tool.config;

import java.util.HashMap;
import java.util.Map;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.Service;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;

/**
 * @author yi qiang
 * @date 2023-12-08 15:37:48
 */
@State(name = "GlueToolConfig", storages = {
        @Storage("glue_tool_config.xml")
})
@Service
public class GlueToolConfig implements PersistentStateComponent<GlueToolConfig.Config> {

    private Config config = new Config();

    public static GlueToolConfig getInstance() {
        return ServiceManager.getService(GlueToolConfig.class);
    }

    @Override
    public @Nullable Config getState() {
        return config;
    }

    @Override
    public void loadState(@NotNull Config state) {
        this.config = state;
    }

    public static class Config {
        /*
         *   {
         *    "https://live-1.test.funnymamu.com/yapi/glue/execute":"xxx1",
         *    "https://live-2.test.funnymamu.com/yapi/glue/execute":"xxx2",
         *   }
         */
        public Map<String, String> items = new HashMap<>();

        public Map<String, String> getItems() {
            return items;
        }

        public void setItems(Map<String, String> items) {
            this.items = items;
        }
    }
}
